package example.controller;

import example.config.MyWebAppConfigurer;
import example.dao.DataTableDto;
import example.dao.Result;
import example.pojo.User;
import example.service.FileService;
import example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

//import example.service.AnswerService;
//import example.service.PaperService;
//import example.service.QuestionService;

@Controller
@RequestMapping({"/user"})
public class UserController {

    private Map<String, Object> map;

//    @Autowired
//    private PaperService paperService;
//    @Autowired
//    private QuestionService questionService;
//    @Autowired
//    private AnswerService answerService;

    @Autowired
    private FileService fileService;

    @Autowired
    private UserService userService;

    @Autowired()
    private MyWebAppConfigurer config;
//    @RequestMapping({"/preinsert"})
//    public String preInsert(HttpServletRequest req) {
//        User user = new User();
//        user.setFlag("0");
//        List<User> users = new ArrayList<User>();
//        users.add(user);
//        req.setAttribute("users", users);
//        return "login";
//    }

    @RequestMapping({"/user_list"})
    public String user_list(HttpServletRequest req) throws Exception {
        List<User> users = new ArrayList<User>();
        users = userService.getUserlistAll();

//        for(User tuser : users) {
//            if (tuser.getUserimg()==null || tuser.getUserimg()==""){
//                tuser.setUserimg("/upload/user.png");
//            }
//        }
        //users.add(user);
        req.setAttribute("users", users);
        return "system/user/user_list";
    }

    @RequestMapping({"/getAllUserList"})
    @ResponseBody
    public List<User> getAllUserList(HttpServletRequest req) throws Exception {
        List<User> users = new ArrayList<User>();
        users = userService.getUserlistAll();
        return users;
    }
    // 用户退出user
    @RequestMapping({"/exit"})
    public String exit(User user, HttpServletRequest req, HttpSession session) throws Exception {
        session.removeAttribute("user");
        session.removeAttribute("id");

        return "redirect:../";
    }
    // 取得当前用户ID
    @RequestMapping({"/getuseridnow"})
    @ResponseBody
    public String getUserIdNow(HttpServletRequest req, HttpSession session) throws Exception {
        return String.valueOf(session.getAttribute("id"));
    }

//    @RequestMapping({"/insert0"})
//    public String insert0(HttpSession session, HttpServletRequest req) throws Exception {
//        return "system/user/user_add";
//    }




    @RequestMapping({"/getUsersTotal"})
    @ResponseBody
    public Integer getUsersTotal(User user, HttpSession session, HttpServletRequest req) throws Exception {
      Result result = new Result();
      List<User> users =  userService.getUserlistByName(user);
      if (users!=null && users.size()>=0) {
          return users.size();
      }else{
          return 0;
      }

    }


    @RequestMapping({"/getUsers"})
    @ResponseBody
    public List<User> getUsers(String name, Integer start,
                               Integer pageSize) throws Exception {
        User user= new User();
        user.setName(name);
        List<User> list;
        if (user != null && user.getName() != null && user.getName() != "") {
            list = userService.getUserlistByName(user);
        } else {
            list = userService.getUserlistAll();
        }

        int endIndex =start + pageSize;

        if (list == null) {
            list = new ArrayList<User>();
        }
        if (list.size() < endIndex) {
            endIndex = list.size();
        }
        List<User> listObject = new ArrayList<User>();
        for (int i = start; i < endIndex; i++) {
//              <th>照片</th>
//                <th>ID</th>
//                <th>姓名</th>
//                <th>邮箱</th>
//                <th>电话</th>
//                <th>操作</th>
            user= new User();;
            user.setUserimg(list.get(i).getUserimg()) ;
            user.setId(list.get(i).getId()) ;
            user.setName(list.get(i).getName()) ;
            user.setEmail(list.get(i).getEmail()) ;
            user.setPassword(list.get(i).getPassword());
            user.setPhonenumber(list.get(i).getPhonenumber()) ;
            listObject.add(user);
        }
        return listObject;

    }

    @RequestMapping({"/getUsersByName"})
    @ResponseBody
    public List<User> getUsersByName(String name) throws Exception {
        User user= new User();
        user.setName(name);
        List<User> list;
        if (user != null && user.getName() != null && user.getName() != "") {
            list = userService.getUserlistByName(user);
        } else {
            list = userService.getUserlistAll();
        }

        if (list == null) {
            list = new ArrayList<User>();
        }

        List<User> listObject = new ArrayList<User>();
        for (int i = 0; i < list.size(); i++) {
//              <th>照片</th>
//                <th>ID</th>
//                <th>姓名</th>
//                <th>邮箱</th>
//                <th>电话</th>
//                <th>操作</th>
            user= new User();;
            user.setUserimg(list.get(i).getUserimg()) ;
            user.setId(list.get(i).getId()) ;
            user.setName(list.get(i).getName()) ;
            user.setPassword(list.get(i).getPassword());
            user.setEmail(list.get(i).getEmail()) ;
            user.setPhonenumber(list.get(i).getPhonenumber()) ;
            listObject.add(user);
        }
        return listObject;

    }

    @RequestMapping({"/addSaveUserData"})
    @ResponseBody
    public Result addSaveUserData(User user, HttpSession session, HttpServletRequest req) throws Exception {

        Result result = new Result();

        if (userService.selectByName(user)) {
            user = userService.insert(user);
            if (user != null) {
                result.setResult("success");
                result.setMessage("操作完成");
                result.setImgUrl(user.getUserimg());
            } else {
                result.setResult("error");
                result.setMessage("操作失败");
                result.setImgUrl("");
            }
        } else {
            result.setResult("error");
            result.setMessage("操作失败");
            result.setImgUrl("");
        }
        return result;
    }

//    @RequestMapping({"/insert"})
//    public String insert(User user, HttpSession session, HttpServletRequest req, MultipartFile pictureFile) throws Exception {
//        if (userService.selectByName(user)) {
//            if (pictureFile != null && pictureFile.getSize() > 0) {
//                String userimg = fileService.upLoadFile(req, pictureFile, "/upload");
//                user.setUserimg(userimg);
//            }
//            userService.insert(user);
//            List<User> users = userService.getUserlistAll();
//            req.setAttribute("users", users);
//        } else {
//            List<User> users = new ArrayList<User>();
//            users = userService.getUserlistAll();
//            req.setAttribute("users", users);
//            req.setAttribute("mes", "有相同用户名存在！");
//        }
//        return "system/user/user_list";
//    }
//
//    // 用户信息修改界面跳转
//    @RequestMapping({"/edit"})
//    public String edit(User user, HttpServletRequest req, HttpSession session) throws Exception {
//
//        if (user == null) {
//            // 当前用户
//            user = (User) session.getAttribute("user");
//        }
//        user = userService.getUserById(user.getId());
//        long count = userService.selectCount();
//
//        req.setAttribute("user0", user);
//        return "system/user/user_edit";
//
//    }

    // 用户信息修改完成
    @RequestMapping({"/updateSaveUserData"})
    @ResponseBody
    public Result updateSaveUserData(User newuser, HttpServletRequest req, HttpSession session) throws Exception {
        User user = userService.getUserById(newuser.getId());
        // 删除原来的图片
        if (user.getUserimg() != null
                && !(user.getUserimg().equals(""))
                && !(newuser.getUserimg().equals( user.getUserimg())) ) {
            String filePath = config.ROOT_PATH + user.getUserimg();
            fileService.deleteFile(filePath);
        }
        //修改信息
        user.setUserimg(newuser.getUserimg());
        user.setName(newuser.getName());
        user.setPassword(newuser.getPassword());
        user.setEmail(newuser.getEmail());
        user.setPhonenumber(newuser.getPhonenumber());
        Result result = new Result();
        user = userService.update(user);
        if (user != null) {
            result.setResult("success");
            result.setMessage("操作完成");
            result.setImgUrl(user.getUserimg());
        } else {
            result.setResult("error");
            result.setMessage("操作失败");
            result.setImgUrl("");
        }
        return result;
    }

//    // 用户信息修改完成
//    @RequestMapping({"/edit2"})
//    public String edit2(User newuser, HttpServletRequest req, HttpSession session, MultipartFile pictureFile) throws Exception {
//
//        User user = userService.getUserById(newuser.getId());
//
//        if (pictureFile != null && pictureFile.getSize() > 0) {
//            // 删除原来的图片
//            if (user.getUserimg() != null && !(user.getUserimg().equals(""))) {
//                String filePath = req.getSession().getServletContext().getRealPath(user.getUserimg());
//                fileService.deleteFile(filePath);
//            }
//
//
//            // 递交图片
//            String userimg = fileService.upLoadFile(req, pictureFile, "/upload");
//
//            //修改图片
//            user.setUserimg(userimg);
//
//
//        }
//
//        user.setName(newuser.getName());
//        user.setPassword(newuser.getPassword());
//        user.setEmail(newuser.getEmail());
//        user.setPhonenumber(newuser.getPhonenumber());
//
//        userService.update(user);
//        List<User> users = userService.getUserlistAll();
//        req.setAttribute("users", users);
//        return "system/user/user_list";
//    }

    @RequestMapping("/delete")
    @ResponseBody
    public Result delete(User user, HttpServletRequest req, HttpSession session) throws Exception {
        // 当前用户
        //User user= (User) session.getAttribute("user");
        user = userService.getUserById(user.getId());
        String imgName="";
        if (user.getUserimg() != null && !(user.getUserimg().equals(""))) {
            imgName= user.getUserimg().replaceFirst(config.uploadPath,"");
            String filePath = config.ROOT_PATH + imgName;
            fileService.deleteFile(filePath);
        }
        Result result = new Result();
        userService.deleteUserById(user);
        result.setResult("success");
        result.setMessage("操作完成");
        result.setImgUrl(user.getUserimg());
        return result;

    }

//
//
//    @RequestMapping({"/upload"})
//    @ResponseBody
//    public Result upload(User newuser, HttpServletRequest req, HttpSession session, MultipartFile pictureFile) throws Exception {
//        Result result = new Result();
//        // 递交图片
//        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req;
//        List<MultipartFile> files = multipartRequest.getFiles("files");
//        String userimg = fileService.upLoadFile(req, files.get(0), "/upload");
//        result.setResult("success");
//        result.setMessage("上传完成");
//        result.setImgUrl(userimg);
//        return result;
//    }


    @RequestMapping({"/forgetPwd"})
    public String forgetPwd() {
        return "forgetPwd";
    }

    @RequestMapping({"/reSetPwd"})
    public String reSetPwd() {
        return "reSetPwd";
    }

//    @RequestMapping({"/setPwd"})
//    public String setPwd(User user, HttpServletRequest req, HttpSession session) throws Exception {
//
//        if (user.getPassword().equals(user.getPassword1())) {
//
//
//            User tuser = userService.getPwdByPhoneOrMail(user);
//
//            if (tuser == null) {
//                req.setAttribute("mes", "邮箱有误!");
//            } else {
//                boolean result = userService.setPwdByMail(user);
//                if (result == true) {
//                    req.setAttribute("mes", "修改成功");
//                } else {
//                    req.setAttribute("mes", "修改失败");
//                }
//            }
//        } else {
//            req.setAttribute("mes", "密码输入不一致！");
//            return "reSetPwd";
//        }
//        return "reSetPwd";
//    }

    @RequestMapping({"/getPwd"})
    public String getPwd(User user, HttpServletRequest req, HttpSession session) throws Exception {
        User tuser = userService.getPwdByPhoneOrMail(user);

        if (tuser == null) {
            req.setAttribute("mes", "邮箱有误!");

        } else {
            req.setAttribute("mes", "你的密码是：" + tuser.getPassword());

        }
        return "forgetPwd";
    }


// 用户查询

    @RequestMapping({"/getUserlistByName"})
    @ResponseBody
    public List<User> getUserlistByName(User user, HttpServletRequest req, HttpSession session) throws Exception {
        List<User> userlist = userService.getUserlistByName(user);
        return userlist;
    }
    @RequestMapping({"/getUserById"})
    @ResponseBody
    public User getUserById(User user, HttpServletRequest req, HttpSession session) throws Exception {
        user= userService.getUserById(user.getId());
        return user;
    }

    /*
         读取表单数据，分页
         *
         */
    @RequestMapping({"/part"})
    @ResponseBody
    public DataTableDto part(DataTableDto dataTableDto,
                             User user, int start,
                             int length, String draw) throws Exception {


        List<User> list;
        if (user != null && user.getName() != null && user.getName() != "") {
            String name = user.getName();
            list = userService.getUserlistByName(user);
        } else {
            list = userService.getUserlistAll();
        }


        int endIndex = dataTableDto.start + dataTableDto.length;
        if (list == null) {
            list = new ArrayList<User>();
        }
        if (list.size() < endIndex) {
            endIndex = list.size();
        }
        List<Object> listObject = new ArrayList<Object>();
        for (int i = dataTableDto.start; i < endIndex; i++) {
//              <th>照片</th>
//                <th>ID</th>
//                <th>姓名</th>
//                <th>邮箱</th>
//                <th>电话</th>
//                <th>操作</th>
            Object[] objects = new Object[6];
            objects[0] = list.get(i).getUserimg();
            objects[1] = list.get(i).getId();
            objects[2] = list.get(i).getName();
            objects[3] = list.get(i).getEmail();
            objects[4] = list.get(i).getPhonenumber();
            objects[5] = list.get(i).getId();
            listObject.add(objects);
        }
        dataTableDto.recordsTotal = list.size();
        dataTableDto.recordsFiltered = list.size();
        dataTableDto.data = listObject;

        return dataTableDto;

    }

        // 用户登录后自动跳转到用户模块
    @RequestMapping({"/login"})
    @ResponseBody
    public Result login(User user, HttpServletRequest req, HttpSession session) throws Exception {
        map = userService.login(user);
        Result result = new Result();

//        服务器跳转和客户端跳转的区别：
//        1.服务器跳转时，地址栏的地址不改变；而客户端跳转的时候，地址栏的地址是会变化的;
//        2.服务器跳转的时候，能够通过request（或者是 model）来传递数据;而客户端跳转的时候是不能传递数据的

        if (map.size() == 0) {
            result.setResult("error");
            result.setMessage("账号密码有误");
            result.setImgUrl("");
            return result;
        }
        for (Entry<String, Object> one : map.entrySet()) {
            if (one.getKey().equals("user")) {
                User reuser = (User) one.getValue();
                session.setAttribute("user", reuser);
                session.setAttribute("id", reuser.getId());
            }
        }
        result.setResult("success");
        result.setMessage("登录成功");
        result.setImgUrl(user.getUserimg());

        List<User> users = new ArrayList<User>();
        users = userService.getUserlistAll();
        req.setAttribute("users", users);

        return result;

    }

//    @RequestMapping({"/getNamelist"})
//    @ResponseBody
//    public List<User> getNamelist(User user, HttpServletRequest req, HttpSession session) throws Exception {
//        List<User> userlist = userService.getUserByName(user);
//        return userlist;
//    }


    // 用户添加
    @RequestMapping({"/yonghutianjia"})
    public String yonghutianjia(User user, HttpServletRequest req, HttpSession session) throws Exception {

        return "admin/yonghutianjia";
    }
//
//    // 用户添加保存
//    @RequestMapping({"/yonghutianjia2"})
//    public String yonghutianjia2(User user, HttpServletRequest req, HttpSession session) throws Exception {
//        if (userService.selectByName(user)) {
//            user = userService.insert(user);
//            List<User> users = new ArrayList<User>();
//            users.add(user);
//            req.setAttribute("users", users);
//            session.setAttribute("user", user);
//        } else {
//            List<User> users = new ArrayList<User>();
//            users.add(user);
//            req.setAttribute("users", users);
//            req.setAttribute("mes", "有相同用户名存在！");
//            return "admin/yonghutianjia";
//        }
//        gotoadminpage(req, session);
//        return "admin/adminmain";
//    }

//    // 用户登录后自动跳转到用户模块
//    @RequestMapping({"/login"})
//    public String login(User user, HttpServletRequest req, HttpSession session) throws Exception {
//        map = userService.login(user);
//        if (map.size() == 0) {
//            req.setAttribute("mes", "账号密码有误");
//            return "login";
//        }
//        for (Entry<String, Object> one : map.entrySet()) {
//            if (one.getKey().equals("user")) {
//                User reuser = (User) one.getValue();
//                session.setAttribute("user", reuser);
//                session.setAttribute("id", reuser.getId());
//            }
//        }
//        user = userService.getUserByName(user);
//        // 管理员
//        if (user.getFlag().equals("1")) {
//
//            this.gotoadminpage(req,session);
//            return "indexAdmin";
//        }
//        // 注册用户
//        for (Entry<String, Object> one : map.entrySet()) {
//            if (one.getKey().equals("user")) {
//                User reuser = (User) one.getValue();
//                session.setAttribute("user", reuser);
//                session.setAttribute("id", reuser.getId());
//            } else if (one.getKey().equals("papers")) {
//                List<Paper> paperlist = (List<Paper>) one.getValue();
//                req.setAttribute("paperlist", paperlist);
//            } else if (one.getKey().equals("queslist")) {
//                List<Question> queslist = (List<Question>) one.getValue();
//                req.setAttribute("queslist", queslist);
//            }
//        }
//        user = userService.getUserByName(user);
//        return "index";
//    }
//
//    public void gotoadminpage(HttpServletRequest req, HttpSession session) throws Exception {
//        User user = (User) session.getAttribute("user");
//        map = userService.login(user);
//        for (Entry<String, Object> one : map.entrySet()) {
//            if (one.getKey().equals("user")) {
//                User reuser = (User) one.getValue();
//                session.setAttribute("user", reuser);
//                session.setAttribute("id", reuser.getId());
//            } else if (one.getKey().equals("paperlist")) {
//                /*<!--我填写过的问卷-->*/
//                List<Paper> paperList = (List<Paper>) one.getValue();
//                paperList=setPagelist(paperList);
//                req.setAttribute("paperlist", paperList);
//            } else if (one.getKey().equals("paperlist0")) {
//                /*<!--0:待审核问卷;-->*/
//                List<Paper> paperlist0 = (List<Paper>) one.getValue();
//                paperlist0=setPagelist(paperlist0);
//                req.setAttribute("paperlist0", paperlist0);
//            } else if (one.getKey().equals("paperlist1")) {
//                /*<!--1:审核通过问卷;发布的问卷-->*/
//                List<Paper> paperlist1 = (List<Paper>) one.getValue();
//                paperlist1=setPagelist(paperlist1);
//                req.setAttribute("paperlist1", paperlist1);
//            } else if (one.getKey().equals("paperlist2")) {
//                /*<!--2:退回的问卷;-->*/
//                List<Paper> paperlist2 = (List<Paper>) one.getValue();
//                paperlist2=setPagelist(paperlist2);
//                req.setAttribute("paperlist2", paperlist2);
//            } else if (one.getKey().equals("paperlist5")) {
//                 /*<!--5:审核历史;-->*/
//                List<Paper> paperlist5 = (List<Paper>) one.getValue();
//                paperlist5=setPagelist(paperlist5);
//                req.setAttribute("paperlist5", paperlist5);
//            } else if (one.getKey().equals("paperlist9")) {
//                  /*<!--9:回收的问卷;-->*/
//                List<Paper> paperlist9 = (List<Paper>) one.getValue();
//                paperlist9=setPagelist(paperlist9);
//                req.setAttribute("paperlist9", paperlist9);
//            } else if (one.getKey().equals("queslist")) {
//                List<Question> queslist = (List<Question>) one.getValue();
//                req.setAttribute("queslist", queslist);
//            }
//        }
//    }
//
//    private List<Paper>  setPagelist(List<Paper>  papelist){
//
//        if (papelist==null || papelist.size()==0) {return papelist;}
//        User user= new User();
//
//        for (int i=0 ;i<=papelist.size()-1; i++)
//        {
//            long id=papelist.get(i).getUid();
//            if (userService.getUserById(id)!=null){
//                String username= userService.getUserById(id).getName();
//                papelist.get(i).setUsername(username) ;
//            }
//
//            if ( papelist.get(i).getTuihuiyuanyin()!=null &&  papelist.get(i).getTuihuiyuanyin().length()>20)
//            {
//                papelist.get(i).setTuihuiyuanyin(papelist.get(i).getTuihuiyuanyin().substring(0,10));
//            }
//            if (papelist.get(i).getIsshenhe().equals("1")) {
//                papelist.get(i).setIsshenhe("通过");
//            } else if (papelist.get(i).getIsshenhe().equals("2")) {
//                papelist.get(i).setIsshenhe("不通过");
//            }  else if (papelist.get(i).getIsshenhe().equals("3")) {
//                papelist.get(i).setIsshenhe("退回");
//            } else if (papelist.get(i).getIsshenhe().equals("9")) {
//                papelist.get(i).setIsshenhe("回收");
//            } else {
//                papelist.get(i).setIsshenhe("");
//            }
//            if (papelist.get(i).getType().equals("xyjy")) {
//                papelist.get(i).setType("校园教育");
//            } else if (papelist.get(i).getType().equals("qysc")) {
//                papelist.get(i).setType("企业市场");
//            }else if (papelist.get(i).getType().equals("zfjg")) {
//                papelist.get(i).setType("政府机构");
//            }else if (papelist.get(i).getType().equals("scyx")) {
//                papelist.get(i).setType("市场营销");
//            }else if (papelist.get(i).getType().equals("shrw")) {
//                papelist.get(i).setType("社会人文");
//            }else{
//                papelist.get(i).setType("--其他--");
//            }
//
//        }
//        return papelist;
//    }
//    // 用户退出
//    @RequestMapping({"/adminpage"})
//    public String adminpage(User user, HttpServletRequest req, HttpSession session) throws Exception {
//        gotoadminpage(req, session);
//        return "admin/adminmain";
//    }
//
//    // 进入后台主页面
//    @RequestMapping({"/adminmain"})
//    public String adminmain(User user, HttpServletRequest req, HttpSession session) throws Exception {
//        gotoadminpage(req, session);
//        return "admin/adminmain";
//    }



    // 个人信息

//    @RequestMapping({"/gerenxinxi"})
//    public String gerenxinxi(User user, HttpServletRequest req, HttpSession session) throws Exception {
//        User u = (User) session.getAttribute("user");
//        map = userService.login(u);
//        if (map.size() == 0) {
//            req.setAttribute("mes", "账号密码有误");
//            return "login";
//        }
//        for (Entry<String, Object> one : map.entrySet()) {
//            if (one.getKey().equals("user")) {
//                User reuser = (User) one.getValue();
//                session.setAttribute("user", reuser);
//                session.setAttribute("id", reuser.getId());
//            } else if (one.getKey().equals("paperlist")) {
//                /*<!--我填写过的问卷-->*/
//                List<Paper> paperList = (List<Paper>) one.getValue();
//                paperList=setPagelist(paperList);
//                req.setAttribute("paperlist", paperList);
//            } else if (one.getKey().equals("paperlist0")) {
//                /*<!--0:待审核问卷;-->*/
//                List<Paper> paperlist0 = (List<Paper>) one.getValue();
//                paperlist0=setPagelist(paperlist0);
//                req.setAttribute("paperlist0", paperlist0);
//            } else if (one.getKey().equals("paperlist1")) {
//                /*<!--1:审核通过问卷;发布的问卷-->*/
//                List<Paper> paperlist1 = (List<Paper>) one.getValue();
//                paperlist1=setPagelist(paperlist1);
//                req.setAttribute("paperlist1", paperlist1);
//            } else if (one.getKey().equals("paperlist2")) {
//                /*<!--2:退回的问卷;-->*/
//                List<Paper> paperlist2 = (List<Paper>) one.getValue();
//                paperlist2=setPagelist(paperlist2);
//                req.setAttribute("paperlist2", paperlist2);
//            } else if (one.getKey().equals("paperlist5")) {
//                 /*<!--5:审核历史;-->*/
//                List<Paper> paperlist5 = (List<Paper>) one.getValue();
//                paperlist5=setPagelist(paperlist5);
//                req.setAttribute("paperlist5", paperlist5);
//            } else if (one.getKey().equals("paperlist9")) {
//                  /*<!--9:回收的问卷;-->*/
//                List<Paper> paperlist9 = (List<Paper>) one.getValue();
//                paperlist9=setPagelist(paperlist9);
//                req.setAttribute("paperlist9", paperlist9);
//
//            } else if (one.getKey().equals("queslist")) {
//
//                List<Question> queslist = (List<Question>) one.getValue();
//
//                req.setAttribute("queslist", queslist);
//            }
//
//        }
//        return "gerenxinxi";
//    }


//    @RequestMapping("/paper")
//    public String paperForId(HttpServletRequest req) {
//        String id = req.getParameter("pid");
//        Long pid = Long.valueOf(id);
//        Paper paper = paperService.selectByPid(pid);
//        req.setAttribute("paper", paper);
//
//        List<Question> questions = questionService.selectByPid(pid);
//        req.setAttribute("questions", questions);
//
//        List<Answer> answers = new ArrayList<Answer>();
//        for (Question q : questions) {
//            answers.addAll(answerService.selectByQid(q.getQid()));
//        }
//        req.setAttribute("answers", answers);
//        return "survery";
//
//
//    }
}
